﻿using OSSUtility.Device;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Ozone.Device
{
    /// <summary>
    /// 扫码枪
    /// </summary>
    public class DevQRScan : DevBase
    {
        public DevQRScan(int CommType, string FSrvIP, int FPort) : base(CommType, FSrvIP, FPort)
        {

        }

        public bool Switch(bool bStart)
        {
            byte[] bytesSend = new byte[] { 0x7E, 0x01, 0x30, 0x30, 0x30, 0x30, 0x40, 0x53, 0x43,
                                            0x4E, 0x45, 0x4E, 0x41, 0x31, 0x3B, 0x03 };
            if (!bStart)
            {
                bytesSend = new byte[] { 0x7E, 0x01, 0x30, 0x30, 0x30, 0x30, 0x40, 0x53, 0x43,
                                            0x4E, 0x45, 0x4E, 0x41, 0x30, 0x3B, 0x03};
            }

            byte[] bytesRecv = session_.sendAndReadByteLock(bytesSend, 300);
            if (bytesRecv != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public string GetBarcode()
        {
            for (int i = 0; i < 10; i++)
            {
                string RecvStr = session_.read();
                if (RecvStr != "")
                    return RecvStr;

                Thread.Sleep(300);
            }

            return "";
        }
    }
}
